<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let num = 30;
        let obj = {
            uname:"张三",
            sex:"男"
        }

        Object.defineProperty(obj,"age",{
            get(){
                console.log("当有人读取 age 的值时，就会自动调用 get 方法，get的返回值就是 age 的值。")
                return num
            },
            set(value){
                console.log("当有人修改 age 的值时，就会自动调用 set 方法 ");
                num = value
            }
        })
    </script>
</body>
</html>